package Thread.pool;

import java.util.concurrent.*;

public class threadPool_runnable {
    public static void main(String[] args) {
//        public ThreadPoolExecutor(int corePoolSize,
//        int maximumPoolSize,
//        long keepAliveTime,
//        TimeUnit unit,
//        BlockingQueue<Runnable> workQueue,
//        ThreadFactory threadFactory,
//        RejectedExecutionHandler handler)
        ExecutorService executor = new ThreadPoolExecutor(3,5,6,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(5),Executors.defaultThreadFactory()
                ,new ThreadPoolExecutor.AbortPolicy());//创建线程池
        Runnable myRunnable = new MyRunnable();
        executor.execute(myRunnable);//将任务交给线程池
        executor.execute(myRunnable);
        executor.execute(myRunnable);
        executor.execute(myRunnable);
        executor.execute(myRunnable);
        executor.execute(myRunnable);
        executor.execute(myRunnable);
        executor.execute(myRunnable);//此时任务队列排满了
        executor.execute(myRunnable);//创建临时线程
        executor.execute(myRunnable);//创捷临时线程
        executor.execute(myRunnable);//启用丢弃策略 并抛抛出异常
    }
}
class MyRunnable implements Runnable{

    @Override
    public void run() {

        System.out.println(Thread.currentThread().getName()+"执行了...");
        System.out.println(Thread.currentThread().getName()+"进入休眠");
        try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
